/* eslint-disable no-restricted-syntax */
import axios from 'axios';
import Cookies from 'js-cookie'
import config from '../config/index'

const { api: {
    devApiBaseUrl, proApiBaseUrl
}} = config

const BaseUrl = process.env.NODE_ENV === 'production' ? proApiBaseUrl : devApiBaseUrl;

export const Service = axios.create({
    baseURL: BaseUrl,
    timeout: 8000,
    method: 'post',
    headers: {
        'Content-Type': 'application/json;charset=UTF-8'
    }
})

Service.interceptors.request.use((config) => {
    config.headers['common'] = Cookies.get('token')
    return config;
}, (err) => {
    return Promise.reject(err)
})

Service.interceptors.response.use((res) => {
    console.log(res)
    return res
}, (err) => {
    return Promise.reject(err)
})
